package com.zhentao.new_z5.controller;

import com.github.pagehelper.PageInfo;
import com.zhentao.new_z5.pojo.User;
import com.zhentao.new_z5.service.UserService;
import com.zhentao.new_z5.vo.UserRoleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    UserService userService;
//    登录判断
    @PostMapping("login")
    public User login(@RequestParam String username,@RequestParam String password){
            return userService.login(username,password);
    }
//    注册
    @PostMapping("UserAdd")
    public boolean UserAdd(@RequestBody User user){
        System.out.println(user);
            try {
                    userService.UserAdd(user);
                    System.out.println(user);
                    userService.UserRole(user.getUid());
                return true;
            }catch (Exception e){
                return false;
            }
    }
//    查询某个用户
    @PostMapping("show")
    public User show(@RequestParam int uid){
        return userService.show(uid);
    }
//    修改用户信息
    @PostMapping("update")
    public boolean update(@RequestBody User user){
        System.out.println(user+"111111111111111111111111111111111111");
        try {
            userService.update(user);
            return true;
        }catch ( Exception e ) {
            return false;
        }
    }
//    分页查询用户信息
    @PostMapping("fontpage")
    public PageInfo<UserRoleVo> findUser(@RequestBody UserRoleVo role){
System.out.println(role+"11111111111113+++++++++++++++++");
        PageInfo<UserRoleVo> pageInfo = userService.findUser(role);
        return pageInfo;
    }
//    删除用户UU
    @DeleteMapping("delete")
    public boolean delete(@RequestBody User user){
        System.out.println(user+"11111111111113+++++++++++++++++");
        try {
            userService.delete(user);
            userService.deleteUR(user);
            return true;
        }catch (Exception  e){
            return false;
        }
    }
}
